﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MayhemWpf.UserControls;

namespace TwilioMayhem.Wpf
{
    /// <summary>
    /// Interaction logic for CallConfig.xaml
    /// </summary>
    public partial class CallConfig : WpfConfiguration
    {
        public CallConfig(string telephoneNumberTo, string telephoneNumberFrom, string voiceXmlUri, string twilioSID, string twilioToken)
        {
            InitializeComponent();

            TelephoneNumberTo = telephoneNumberTo;
            TelephoneNumberFrom = telephoneNumberFrom;
            VoiceXmlUri = voiceXmlUri;
            TwilioSID = twilioSID;
            TwilioToken = twilioToken;
        }

        public override string Title
        {
            get
            {
                return "Call telephone";
            }
        }

        public string TelephoneNumberTo { get; set; }

        public string TelephoneNumberFrom { get; set; }

        public string VoiceXmlUri { get; set; }

        public string TwilioSID { get; set; }

        public string TwilioToken { get; set; }

        public override void OnLoad()
        {
            TelephoneNumberBoxTo.Text = TelephoneNumberTo;
            TelephoneNumberBoxFrom.Text = TelephoneNumberFrom;
            VoiceXmlUriBox.Text = VoiceXmlUri;
            TwilioSIDBox.Text = TwilioSID;
            TwilioTokenBox.Text = TwilioToken;
        }

        public override void OnSave()
        {
            if (!(string.IsNullOrEmpty(TelephoneNumberBoxFrom.Text) || string.IsNullOrEmpty(TelephoneNumberBoxTo.Text) || string.IsNullOrEmpty(VoiceXmlUriBox.Text) || string.IsNullOrEmpty(TwilioSIDBox.Text) || string.IsNullOrEmpty(TwilioTokenBox.Text)))
            {
                TelephoneNumberTo = TelephoneNumberBoxTo.Text;
                TelephoneNumberFrom = TelephoneNumberBoxFrom.Text;
                VoiceXmlUri = VoiceXmlUriBox.Text;
                TwilioSID = TwilioSIDBox.Text;
                TwilioToken = TwilioTokenBox.Text;
            }

        }

        private void Box_TextChanged(object sender, TextChangedEventArgs e)
        {
            CanSave = true;
            if (string.IsNullOrEmpty(TelephoneNumberBoxFrom.Text) || string.IsNullOrEmpty(TelephoneNumberBoxTo.Text) || string.IsNullOrEmpty(VoiceXmlUriBox.Text) || string.IsNullOrEmpty(TwilioSIDBox.Text) || string.IsNullOrEmpty(TwilioTokenBox.Text))
            {
                CanSave = false;
            }
        }

        private void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
        {
            System.Diagnostics.Process.Start(e.Uri.ToString());
        }

    }
}
